﻿using System;
using System.Collections.Generic;
using viNews.Classes;
using viNews.Controllers;
using visinia.SmartEngine;
using visinia.SmartEngine.Modules;

public partial class Modules_viNews_HeadLine : WebModule
{
    protected void Page_Load(object sender, EventArgs e)
    {
        List<News> list = DataFilterController.GetFilteredData(ModuleId);
        if (list == null)
            return;
        if (list.Count > 0)
        {
            News news = list[0];
            if (news == null)
                return;
            TITLE.Text = news.Title;
            TITLE.NavigateUrl = news.Url;
            AUTHOR.Text = news.Author;
            SUMMARY.Text = news.Summary;
            MoreLink.NavigateUrl = news.Url;
            DATE.Text = news.Date.ToString("f");
            if (!string.IsNullOrEmpty(news.ImageUrl))
                IMAGE.ImageUrl = WebRoots.GetResourcesRoot + news.ImageUrl;
            else
                IMAGE.Visible = false;
        }
    }

    public string TrimSummary(string summary)
    {
        if (summary.Length > 150)
            return summary.Remove(150) + "...";
        return summary;
    }
}
